=<template>
    <div class="xl-table">
        <div class="xl-table-content">
            <xlTable
                    :columns="columns"
                    :dataSource="data"
                    rowKey="id"
                    :pagination="pagination"
                    :loading="loading"
                    :confirmLoading="confirmLoading"
                    @change="handleTableChange"
                    bordered
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                >
                <template v-slot:demandStatus="scope">
                    <a :style="{color:getColor(scope.text)}">{{getStatus(scope.text,scope.option)}}</a>
                </template>
                <template v-slot:action="scope" v-if="user">
                    <div v-if="loginUserType == 1">
                        <div v-if="scope.record.demandStatus == 1 || scope.record.demandStatus == 6">
                            <a @click="editForm(scope.record)">编辑</a>
                            <a-divider type="vertical"/>
                            <a-dropdown>
                                <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                                <a-menu slot="overlay">
                                    <a-menu-item @click="seeForm(scope.record)">
                                        <a>查看</a>
                                    </a-menu-item>
                                    <a-menu-item>
                                        <a-popconfirm title="确定删除吗?" @confirm="() => delForm(scope.record.id)">
                                            <a>删除</a>
                                        </a-popconfirm>
                                    </a-menu-item>
                                </a-menu>
                            </a-dropdown>
                        </div>
                        <div v-else>
                            <a @click="seeForm(scope.record)">查看</a>
                            
                        </div>
                    </div>
                    <div v-else>
                        <div v-if="scope.record.demandStatus == 2">
                            <a @click="seeForm(scope.record)">查看</a>
                            <a-divider type="vertical"/>
                            <a @click="abutmentForm(scope.record)" >需求对接</a>
                        </div>
                        <div v-else>
                            <a @click="seeForm(scope.record)">查看</a>
                            <a-divider type="vertical" v-if="scope.record.demandStatus == 4 && (scope.record.adviserName == '' || scope.record.serviceProductName == '')"/>
                            <a @click="issueForm(scope.record)" v-if="scope.record.demandStatus == 4 && (scope.record.adviserName == '' || scope.record.serviceProductName == '')">分配</a>
                        </div>
                        
                    </div>
                </template>
                <template v-slot:action="scope" v-else>
                    <a @click="seeForm(scope.record)">查看</a>
                    <a-divider type="vertical" v-if="scope.record.demandStatus == 1"/>
                    <a-dropdown v-if="scope.record.demandStatus == 1">
                        <a class="ant-dropdown-link">审核 <a-icon type="down"/></a>
                        <a-menu slot="overlay">
                            <a-menu-item @click="pass(scope.record)">
                                <a>通过</a>
                            </a-menu-item>
                            <a-menu-item @click="refuse(scope.record)">
                                <a>拒绝</a>  
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </template>
            </xlTable>
        </div>
        <stackForm :column='2' ref="xlForm" @handleOk="handleOk"></stackForm>
        <stackSee  ref="seeForm"></stackSee>
        <issuesForm ref="issuesForm"></issuesForm>
        <xlAdd ref="addData" @handleOk="handleOk"></xlAdd>
    </div>
</template>

<script>
    import xlMixin from '../../../../mixin/index'
    import xluploadFile from '@/components/formUntil/xluploadFile'
    import xlAdd from '../add/add'
    import stackForm from '../add/add'
    import issuesForm from './model/issue'
    // import stackSee from '../add/add'
    import {demandBasePass,demandBaseRefush,demandBaseAbutment} from '@/assets/api/new'
    import {companyDetailGet} from "@/assets/api/supermarket";
     
    export default {
        name: "index",
        mixins:[xlMixin],
        data(){
            return{
                confirmLoading:false,
                loginUserType:''
            }
        },
        props:{
            columns:{
                type:Array,
                default:()=>{
                    return []
                }
            },
            demandName:String,
            url:{
                type:Object,
                default:()=>{
                    return {
                        list: "",
                        add: '',
                        edit: '',
                        delete: "",
                        deleteBatch: "",
                        exportXlsUrl: "",
                        importExcelUrl: ""
                    }
                }
            },
            code:String,
            user:Boolean
        },
        watch:{
            columns(){
                this.paramMore.demandDomainCode = this.code
                this.formatMerge()
                this.pageOnload()
            }
        },
        created(){
            this.paramMore.demandDomainCode = this.code
            this.formatMerge()
            this.pageOnload()
            this.loginUserType = this.$store.getters.userInfo.loginUserType
        },
        methods:{
            // 需求对接
            abutmentForm(data){
                demandBaseAbutment({param: data.id}).then(result => {
                    console.log(result)
                    this.pageOnload()
                })
            },
            // 分配
            issueForm(data){
                console.log(data,111)
                this.$refs.issuesForm.visible = true
                this.$refs.issuesForm.formatForm(data)
            },
            addForm() {
                if(this.code == 'SD108001'){
                     this.$refs.addData.tableTitle = '新增'
                    this.$refs.addData.visible = true
                    this.$refs.addData.confirmLoading = false
                    this.$refs.addData.formatForm(this.columns)
                }
                if(this.code != 'SD108001'){
                    if (this.user) {
                        let formData = {
                            proposerName:this.$store.getters.userInfo.loginUserName,
                            creditCode: this.$store.getters.userInfo.busiUserCode
                        }
                        companyDetailGet({param: this.$store.getters.userInfo.busiUserCode})
                            .then(res => {
                                let companyInfo = res.result.companyBase || {}
                                let financeInfo = res.result.companyFinanceInfo || {}
                                let ipCount = res.result.companyIPCount || {}
                                let employCount = res.result.companyEmployeeSummarize || {}
                                formData = {
                                    proposerName:this.$store.getters.userInfo.loginUserName,
                                    creditCode: this.$store.getters.userInfo.busiUserCode,
                                    companyName: companyInfo.name,
                                    registerAddress: companyInfo.regAddress,
                                    taxAddress: companyInfo.regAddress,
                                    loanedStatus: '2',
                                    financingStatus: '2',
                                    salesIncome: financeInfo.totalSalesT,
                                    rdFound: financeInfo.totalRdFoundT,
                                    totalIncome: financeInfo.totalIncomeT,
                                    totalTax: financeInfo.totalTaxT,
                                    patentNum: ipCount.patentInventionNum,
                                    techStaffNum: employCount.techStaffSize,
                                    doctorNum: employCount.doctorSize,
                                    ht: '2',
                                    contacts: companyInfo.contactName||companyInfo.operName,
                                    contactNumber: companyInfo.contactTel
                                }
                            }).finally(() => {
                            this.$refs.xlForm.tableTitle = '新增'
                            this.$refs.xlForm.formatData(this.columns)
                            this.$refs.xlForm.visible = true
                            this.$refs.xlForm.confirmLoading = false
                            this.$refs.xlForm.formatForm(formData)
                            this.$refs.xlForm.type = 1
                        })
                    } else {
                        this.$refs.xlForm.tableTitle = '新增'
                        this.$refs.xlForm.formatData(this.columns)
                        this.$refs.xlForm.visible = true
                        this.$refs.xlForm.confirmLoading = false
                        this.$refs.xlForm.formatForm({
                            proposerName:this.$store.getters.userInfo.loginUserName,
                            creditCode: this.$store.getters.userInfo.busiUserCode
                        })
                        this.$refs.xlForm.type = 1
                    }
                }
            },
            editForm(data){
                if(this.code == 'SD108001'){
                    this.$refs.addData.tableTitle = '编辑'
                    this.$refs.addData.formatForm(data)
                    this.$refs.addData.visible = true
                }
                if(this.code != 'SD108001'){
                    //修改方法
                    this.$refs.xlForm.tableTitle = '修改'
                    this.$refs.xlForm.formatData(this.columns)
                    this.$refs.xlForm.visible = true
                    this.$refs.xlForm.confirmLoading = false
                    this.$refs.xlForm.formatForm(data)
                    this.$refs.xlForm.type = 2
                }

              
            },
            // seeForm(data){
            //     if(this.demandName == '云资源需求'){
            //         this.$refs.addData.tableTitle = '查看'
            //         this.$refs.addData.formatForm(data)
            //         this.$refs.addData.visible = true
            //     }
            // },
            getStatus(text,option){
                return option.typeData.filter(item=>item.dataValue == text)[0]?.dataName || '--'
            },
            getColor(text){
                if(text == 1){
                    return 'orange'
                }
                if(text == 2){
                    return 'green'
                }
                if(text == 6){
                    return 'red'
                }
            },
            pass(data){
                demandBasePass({param:data.id})
                .then(result =>{
                    this.$message.success( '审核通过');
                    this.pageOnload()
                })
            },
            refuse(data){
                demandBaseRefush({param: data.id}).then(result =>{
                    this.$message.success( '审核拒绝');
                    this.pageOnload()
                })
            }
        },
        components:{
            xluploadFile,
            xlAdd,
            issuesForm
        }
            
    }
</script>

<style scoped lang="less">
    .xl-table{
        .xl-table-content{
            padding: 16px;
        }
    }
</style>